<template>
  <div class="container" @click="handleGalleryClose">
    <div class="container__wrapper">
      <swiper :options="swiperOptions">
        <swiper-slide v-for="item in imgs" :key="item">
          <img :src="item" class="container__wrapper__img" />
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  name: "CommonGallery",
  props: {
    imgs: Array,
  },
  data() {
    return {
      swiperOptions: {
        pagination: {
          el: ".swiper-pagination",
          // 分页器样式类型
          type: "fraction",
        },
        // 将observe应用于Swiper的祖先元素。
        observer: true,
        observeParents: true,
      },
    };
  },
  methods: {
    handleGalleryClose() {
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
.container ::v-deep .swiper-container {
  overflow: inherit;
}
.container {
  z-index: 9;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: #000;
  &__wrapper {
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    &__img {
      width: 100%;
    }
    .swiper-pagination {
      color: #fff;
      bottom: -1rem;
    }
  }
}
</style>